/**
 *
 */
package com.wilmar.process.web.taglibs;

import java.io.IOException;

import javax.servlet.jsp.JspWriter;

import com.wilmar.process.enumerate.EnumProcessTagSupportPublicAttribute;

/**
 * 
 * @author 周立波 E-mail: zhoulibo_java@msn.cn
 * @version 1.0 日期2009-8-5 时间04:15:51
 */
public class ProcessCheckBoxTag extends ProcessTagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 241258187199471960L;
	private String value;
	private String checked;
	private String disabled;

	/**
	 * ork.web.servlet.tags.RequestContextAwareTag#doStartTagInternal()
	 */
	protected int doStartTagInternal() throws Exception {

		boolean readonlyflag = false;
		boolean checkedflag = false;
		boolean disabledflag = false;
		String value_ = "";

		if (this.disabled != null)
			disabledflag = Boolean.valueOf(this.disabled);
		if (super.readonly != null)
			readonlyflag = Boolean.valueOf(super.readonly);
		if (super.name != null && super.getAttribute(super.name) != null) {
			value_ = super.getAttribute(super.name);
			checkedflag = true;
		}
		if (this.checked != null)
			checkedflag = Boolean.valueOf(this.checked);

		StringBuffer html = new StringBuffer();
		html.append("<input type=\"checkbox\" ");

		if (super.getName() != null && !readonlyflag) {
			html.append(" name=\"");
			html.append(super.getName());
			html.append("\"");
		}
		if (super.getId() != null && !readonlyflag) {
			html.append(" id=\"" + super.getId() + "\"");
		}
		if (this.value != null && !readonlyflag) {
			html.append(" value=\"");
			html.append(this.value);
			html.append("\"");
		}
		if (disabledflag || readonlyflag) {
			html.append(" disabled ");
		}
		if (checkedflag)
			html.append(" checked ");
		if (this.getCssStyle() != null) {
			html.append(" style=\"");
			html.append(this.getCssStyle());
			html.append("\" ");
		}
		if (this.getCssClass() != null) {
			html.append(" class=\"");
			html.append(this.getCssClass());
			html.append("\"");
		}
		super.appendPublicAttribute(html,
				EnumProcessTagSupportPublicAttribute.ONCLICK);
		html.append(" />");

		if (readonlyflag) {
			html.append("<input type=\"hidden\"");
			if (super.name != null) {
				html.append(" name=\"");
				html.append(super.name);
				html.append("\"");
			}
			if (super.id != null && !readonlyflag) {
				html.append(" id=\"" + super.id + "\"");
			}
			html.append(" value=\"" + value_ + "\" >");
		}

		JspWriter outer = this.pageContext.getOut();
		try {
			outer.write(html.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getValue() {
		return value;
	}

	public String getChecked() {
		return checked;
	}

	public void setChecked(String checked) {
		this.checked = checked;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
